package com.mall.auth.controller;

import com.mall.auth.service.AuthService;
import com.mall.common.LoginMallUser;
import com.mall.common.domain.MallUser;
import com.mall.common.domain.response.JwtResponse;
import com.mall.common.result.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wangy
 * @version 1.0
 * @description: TODO
 */
@RestController
public class AuthController {
    @Resource
    private AuthService authService;

    /**
     * 登录
     *
     * @param loginMallUser 参数
     * @return Result<JwtResponse>
     */
    @PostMapping("login")
    public Result<JwtResponse> login(@RequestBody LoginMallUser loginMallUser) {
        JwtResponse login = authService.login(loginMallUser);
        return Result.success(login);
    }

    /**
     * 发送验证码
     *
     * @param phone 参数
     * @return Result
     */
    @GetMapping("sendCode/{phone}")
    public Result sendCode(@PathVariable String phone) {
        authService.sendCode(phone);
        return Result.success();
    }

    /**
     * 获取用户信息
     *
     * @return Result<MallUser>
     */
    @GetMapping("info")
    public Result<MallUser> info() {
        MallUser info = authService.info();
        return Result.success(info);
    }
    /**
     * 注销
     *
     * @return Result
     */
    @GetMapping("logout")
    public Result logout() {
        authService.logout();
        return Result.success();
    }

}
